package com.yakami.ocean.view.activity.base;

import android.content.Context;
import android.content.res.Resources;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.widget.TextView;

import com.yakami.ocean.AppManager;
import com.yakami.ocean.R;
import com.yakami.ocean.utils.IntentHelper;
import com.yakami.ocean.utils.Tools;

import butterknife.Bind;
import butterknife.ButterKnife;
import nucleus.view.NucleusActivity;

public abstract class BaseActivity extends NucleusActivity {

    @Bind(R.id.toolbar_title) protected TextView mTitle;
    @Bind(R.id.toolbar) protected Toolbar mToolbar;
    protected Resources mRes;
    protected Context mContext;
    protected Context mAppContext;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(onBindLayout());

        ButterKnife.bind(this);

        setSupportActionBar(mToolbar);

        mRes = getResources();
        mContext = getContext();
        mAppContext = AppManager.context;
    }

    protected abstract int onBindLayout();

    public void toast(String str) {
        Tools.toast(getContext(), str);
    }

    public Context getContext() {
        return BaseActivity.this;
    }

    public int getStatusBarHeight() {
        int result = 0;
        int resourceId = getResources().getIdentifier("status_bar_height", "dimen", "android");
        if (resourceId > 0) {
            result = getResources().getDimensionPixelSize(resourceId);
        }
        return result;
    }

    public int getNavigationBarHeight() {
        int resourceId = mRes.getIdentifier("navigation_bar_height", "dimen", "android");
        if (resourceId > 0) {
            return mRes.getDimensionPixelSize(resourceId);
        }
        return 0;
    }

    public IntentHelper getIntentHelper() {
        return IntentHelper.newInstance(getIntent());
    }
}
